<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>发表帖子评论 - 夜读书</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0">
    <meta name="format-detection" content="telephone=no">
    <meta name="description" content="夜读书,帖子">
    <meta name="keywords" content="夜读书，帖子">
    <link rel="stylesheet" href="{{ asset('/style/css/faxian.css') }}">
    <script src="{{ asset('/scripts/jquery/jquery-1.11.3.min.js') }}"></script>
    <script type="text/javascript" charset="utf-8" src="{{url('editor/ueditor1_4_3_3/ueditor.config.js')}}"></script>
    <script type="text/javascript" charset="utf-8" src="{{url('editor/ueditor1_4_3_3/ueditor.all.js')}}"> </script>
    <script type="text/javascript" charset="utf-8" src="{{url('editor/ueditor1_4_3_3/lang/zh-cn/zh-cn.js')}}"></script>    
</head>
<body class="ns-cricle-bg ">
    <div id="container">
        <div class="mod-post_pinglun">
            <form name="form" id="form" method="post" action="" enctype="multipart/form-data">
            <input type="hidden" name="_token" value="{{ csrf_token() }}" />
            <input type="hidden" name="tieziid" id="tieziid" value="{{$id}}" />
            <div class="mod-pubtiezi">
                <div class="qz-publish-wrap-header">
                    <a href="javascript:;" onClick="javascript:history.back(-1);"><div class="mod-btn is-gray">取消</div></a>
                    <div class="" style="font-size:16px;">发表评论</div>
                    <div class="mod-btn is-green">发表</div>
                </div>
                <div class="publish-content">
                    <script id="pubtiezi" name="pubtiezi" type="text/plain">写点什么吧...</script>     
                </div>
            </div>
            </form>
        </div>
    </div>
<script type="text/javascript">
    //实例化编辑器
    var ue = UE.getEditor('pubtiezi',{
        wordCount: true, //开启字数统计
        elementPathEnabled: false,//是否启用元素路径，默认是显示
        maximumWords: 300,       //允许的最大字符数
        initialContent: '',    //初始化编辑器的内容,也可以通过textarea/script给值，看官网例子
        //autoClearinitialContent: true, //是否自动清除编辑器初始内容，注意：如果focus属性设置为true,这个也为真，那么编辑器一上来就会触发导致初始化的内容看不到了
        pasteplain: true,  //是否默认为纯文本粘贴。false为不使用纯文本粘贴，true为使用纯文本粘贴
        enableContextMenu: false, //关闭右键菜单功能
        //imageUrlPrefix: "http://localhost:4176", /* 图片访问路径前缀 */
        //imagePathFormat: "/UploadFiles/{yyyy}{mm}{dd}/{time}{rand:6}",/* 上传保存路径,可以自定义保存路径和文件名格式 */
        //urlTarget: "Email",
        //initialFrameWidth: 740, //初始化宽度
        initialFrameHeight: 200, //初始化高度
        autoHeightEnabled: true, //关闭高度自适应
        enableAutoSave: false //禁止自动保存
        ,toolbars: []
    });

    ue.ready(function() {
        //默认显示内容
        ue.setContent('<p style="color:silver">写点什么吧...</p>');
        //文本框获取焦点时清空默认显示的内容
        ue.addListener("focus", function(){
            if(UE.getEditor('pubtiezi').getContentTxt() == '写点什么吧...'){
                ue.setContent('');
            }
        });
        //文本框是去焦点时,若内容为空则显示默认显示的内容
        ue.addListener("blur", function(){
            if(!ue.getContent()){
                ue.setContent('<p style="color:silver">写点什么吧...</p>');
            }
        });
    });

    $('.is-green').click(function(){
        //判断评论容是否为空
        if(UE.getEditor('pubtiezi').getContentTxt() == '写点什么吧...')
        {
            alert('请输入评论内容');
            return;
        }
        if(!UE.getEditor('pubtiezi').hasContents())
        {
            alert('请输入评论内容');
            return;
        }
        //发表评论
        $.ajax({
            type : 'POST',
            url : '{{url('tiezi/pubtiezi_pinglun')}}',
            data : {
                'tieziid' : $('#tieziid').val(),
                'content' : UE.getEditor('pubtiezi').getContent()
            },
            dataType : 'html',
            success : function(data) {
                 window.location.href = '{{url('tiezi/tiezipinglun')}}/' + '{{$id}}';
            },
            error : function(e) {
                //console.log(e);
                alert('发表失败');
            }
        });
    });  
</script>
</body>
</html>
